/*
 * @lc app=leetcode.cn id=1013 lang=javascript
 *
 * [1013] 将数组分成和相等的三个部分
 */

// @lc code=start
/**
 * @param {number[]} arr
 * @return {boolean}
 */
var canThreePartsEqualSum = function (arr) {
  const res = [];
  const sum = arr.reduce((pre, cur) => {
    res.push(cur + pre)
    return cur + pre;
  }, 0);
  const index1 = res.indexOf(sum / 3);
  const index2 = res.lastIndexOf(sum / 3 * 2, arr.length - 2);
  if (index1 === -1 || index2 === -1) return false;
  return index2 > index1;
};
// @lc code=end
